Minecraft: run the server as the letsbuilda user - #28
Merged
Conversation
The itzg image defaults to UID/GID 1000, but /opt/letsbuilda/minecraft
is owned by letsbuilda, so world data ended up owned by the wrong user.
Look up the letsbuilda account's UID/GID at deploy time with getent and
write them to the compose project's .env, which docker compose reads for
${UID:?}/${GID:?} interpolation into the container environment. The
image's entrypoint then chowns /data and drops privileges to that user
on startup. No numeric ID is hardcoded, and compose.yaml stays a plain
static file so Dependabot keeps bumping the pinned image.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NoJDrw76ZHLTcBG8JTWW2c
Run the whole container as letsbuilda from the start rather than having the image's root entrypoint step down: no root process ever exists in the container, and nothing can chown the bind mount behind our back. /data ownership was already fixed on the host, and any future drift is a manual chown. The getent-to-.env lookup is unchanged; compose now interpolates the IDs into user: instead of the container environment. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NoJDrw76ZHLTcBG8JTWW2c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Run the Minecraft container as the
letsbuildahost account instead of the itzg image's default UID/GID 1000, without hardcoding the numeric ID anywhere in the repo.ansible.builtin.getentonpasswd/letsbuilda— read-only, fails fast if the account is missing) and writes the IDs to/opt/letsbuilda/minecraft/.env.compose.yamlsetsuser: "${UID:?}:${GID:?}", interpolated by docker compose from that.env(docker_compose_v2picks it up fromproject_srcautomatically). The:?makes a missing.envfail the deploy loudly instead of silently falling back to the image default.Why
/opt/letsbuilda/minecraft/is owned byletsbuilda, but the image was running the server as its built-in default (1000), so world data ended up owned by the wrong user.With the compose
user:directive the container starts asletsbuildafrom the first process — the image's root entrypoint/step-down machinery is skipped entirely, no root process ever exists in the container, and nothing can chown the bind mount. (/dataownership was already fixed on the host; the alternativeUID/GIDenv-var mode would instead keep a root entrypoint that auto-chowns/data, trading the rootless property for self-healing ownership.)compose.yamlstays a plain static file at the same path, so the Dependabotdocker-composewatcher keeps bumping the pinned image.Validation
check-yaml, yamlfix, and whitespace hooks pass on the changed filesansible-playbook --syntax-checkandansible-lintpass clean (productionprofile)Deploy notes
docker inspect --format '{{.Config.User}}'should show1001:1001, and the java process runs asletsbuildafrom startup.docker compose execshell now runs as the unnamed UID (I have no name!prompt) — cosmetic and expected./dataownership drift (restored backup, files copied in as root) is a manualchown -R letsbuilda:letsbuilda, since the container can no longer fix ownership itself.🤖 Generated with Claude Code
https://claude.ai/code/session_01NoJDrw76ZHLTcBG8JTWW2c
Generated by Claude Code